Category: Accessible Games
I've been trying to post this on both audiogames.net and blastbay.com's forums all day but I keep getting a weird error message when I try. But I need some help with some BGT code. If you've kept up with my threads on Blastbay you'll know I've been working on a Simon style game for the last few weeks and, over the last week or two, have made some pretty good progress. But I'm having a little trouble at the moment. I'm coding a Keyboard Practice mode into the game and I've got a few errors I need to work out, well just one really at the moment. Wen I first tried to code this BGT gave me an error about no matching signatures for Play Tone. So I'm trying to code that into the game. But I've been getting an error message regarding the Play Tone code itself regarding an expected left Parentheses. Given how misleading BGT error messages can sometimes be I'm wondering if it could actually be something like an incorrect character or characters in that code or the code is in the wrong place. I'll post the code below, assuming of course that I don't get the same error I've gotten on both audiogames and Blastbay. If anyone's curious the error I get when I try to post on those forums goes something like [i] was opened within itself, this is not allowed. I need hardly point out that I haven't a clue what that means, much less whether it's within my power to correct that. But my code is below. Thanks in advance for any assistance.
#include "dynamic_menu.bgt"
sound music;
sound error;
sound[] tone(4);
void main()
{
music.load("sounds/music.wav");
music.play_looped();
music.volume = -10;
tone[0].load("sounds/tone[0].wav");
tone[0].volume = -10;
tone[1].load("sounds/tone[1].wav");
tone[1].volume = -10;
tone[2].load("sounds/tone[2].wav");
tone[2].volume = -10;
tone[3].load("sounds/tone[3].wav");
tone[3].volume = -10;
error.load("sounds/error.wav");
error.volume = -10;
tts_voice voice;
show_game_window("BP Simon");
voice.speak_wait("Welcome to BP Simon!");
dynamic_menu menu;
menu.add_item_tts("Start game");
menu.add_item_tts("Keyboard practice");
menu.add_item_tts("Exit game");
menu.allow_escape = true;
menu.wrap = true;
int choice=menu.run("Use the up and down arrow keys to select an option, then press enter..", true);
if(choice==1)
{
music.stop();
play_round();
music.play_looped();
}
else if(choice==2)
{
music.stop();
keyboard_practice();
music.play_looped();
}
voice.speak_wait("Thanks for playing BP Simon! Bye now.");
}
void play_round()
{
return;
}
void keyboard_practice()
{
tts_voice voice;
voice.speak_wait("Press the arrow keys to learn the tones they generate.");
voice.speak_wait("Press escape when you're finished.");
while(!key_pressed(KEY_ESCAPE))
void play_tone(int i)
{
tone[i].stop();
tone[i].play();
}
{
if(key_pressed(KEY_LEFT))
{
play_tone(0);
}
else if(key_pressed(KEY_DOWN))
{
play_tone(1);
}
else if(key_pressed(KEY_RIGHT))
{
play_tone(2);
}
else if(key_pressed(KEY_UP))
{
play_tone(3);
}
wait(5);
}
}
Well, you don't need to have two declarations of tts_voice voice. I would declare this at the top, and then just route everything through that. Also, when you have your goodbye message, put an if statement that does this if escape or exit is chosen. Then, don't put the end brace that ends void main. This section of code would go like this:
}
else if (choice==3) {
//and escape, of course goes here too
voice.speak_wait("Thanks for playing BP Simon! Bye now.");
exit();
}
//do not put the ending brace to void main here
void keyboard_practice () {
When you start your while loop, you don't have a {.
Also, there is an easier way to do keyboard_practice:
void keyboard_practice () {
voice.speak_wait("Press the arrow keys to learn the tones they generate.");
voice.speak_wait("Press escape when you're finished.");
while true {
if (key_pressed(KEY_LEFT)) {
//tone for left, like tone[0].play();
}
//do the same for the next tones
if (key_pressed(KEY_ESCAPE)) {
voice.speak_wait("OK, back to the menu.");
int choice=menu.run("Use the up and down arrow keys to select an option, then press enter.", true);
}
wait(5);
}
Like I said though, when I do that I get an error about no matcing signatures for Play Tone. That's the error I got first.
Ok. I see I overlooked something. Your tones are called tone1.wav, tone2.wav, etc. Right? You call them as if they were items in an array.
Actually it's 0 to 3. And you actually do ned to declare the TTS voice each time. I tried removing that second declaration like you said and it gave me an error about it.
Did you declare it as a global variable, as in before void main? That's what I would have done.
Hmmm. Maybe I'll try that. But I'm still not entirely clear on the Play Tone function.
For scalability, you might consider changing the block of code which assigns tone files to a for - next loop. That way, you only have to change a line or two of code, rather than add more lines later on, in the event you want to add more sounds.
Kai
Well I don't foresee adding more sounds to this particular game, unless of course I decided in the future to ditch SAPI and go entirely with prerecorded speach.